function xhePrint() {


    this.control = '';
    this.options = [];

    //模块属性
    this.option = {
        id: '',
        class: '',
        text: '',
        color: '#000000',
        top: 'auto',
        left: 'auto',
        right: 'auto',
        bottom: 'auto',
        fontSize: '12px',
        fontFamily: '',
        fontWeight: '',
        textAlign: 'left',
        verticalAlign: 'middle'
    };
    //根据属性设置模块
    this.load = function () {

        try {

            var vHtml = "";

            if (this.options.length > 0) {

                for (let i = 0; i < this.options.length; i++) {

                    let position = "";

                    if (this.options[i].top != "auto") {
                        position += "top: " + this.options[i].top + "; ";
                    }
                    if (this.options[i].left != "auto") {
                        position += "left: " + this.options[i].left + "; ";
                    }
                    if (this.options[i].right != "auto") {
                        position += "right: " + this.options[i].right + "; ";
                    }
                    if (this.options[i].bottom != "auto") {
                        position += "bottom: " + this.options[i].bottom + "; ";
                    }

                    let fontStyle = "";

                    fontStyle += "font-size: " + this.options[i].fontSize + "; ";
                    fontStyle += "text-align: " + this.options[i].textAlign + "; ";
                    fontStyle += "vertical-align: " + this.options[i].verticalAlign + "; ";

                    if (this.options[i].fontFamily != "") {
                        fontStyle += "font-family: " + this.options[i].fontFamily + "; ";
                    }
                    if (this.options[i].fontWeight != "") {
                        fontStyle += "font-weight: " + this.options[i].fontWeight + "; ";
                    }

                    vHtml += "<div id=\"" + this.options[i].id + "\" class=\"" + this.options[i].class + "\" style=\"position: absolute; color:" + this.options[i].color + "; " + position + " " + fontStyle + "\">" + this.options[i].text + "</div>";
                }
            }

            document.getElementById(this.control).innerHTML = vHtml;
        }
        catch (e) { }
    };
    //打印事件
    this.print = function () {

        try {

            $("#" + this.control).printArea();
        }
        catch (e) {
            alert("打印出错:" + e);
        }
    };
}

(function ($) {
    var printAreaCount = 0;
    $.fn.printArea = function () {
        var ele = $(this);
        var idPrefix = "printArea_";
        removePrintArea(idPrefix + printAreaCount);
        printAreaCount++;
        var iframeId = idPrefix + printAreaCount;
        var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
        iframe = document.createElement('IFRAME');
        $(iframe).attr({
            style: iframeStyle,
            id: iframeId
        });
        document.body.appendChild(iframe);
        var doc = iframe.contentWindow.document;
        $(document).find("link").filter(function () {
            return $(this).attr("rel").toLowerCase() == "stylesheet";
        }).each(
            function () {
                // 这里是在将网页中的所有css引入，即打印区域的css如果是link进来的，可以设置在网页的任何位置
                doc.write('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >');
            });
        doc.write($(ele).prop('outerHTML')); // 将待打印元素原封不动的引入
        doc.close();
        var frameWindow = iframe.contentWindow;
        frameWindow.close();
        frameWindow.focus();
        // 必须等待frame加载完成后再打印，否则可能在某些浏览器中打印不出东西。
        frameWindow.onload = function () {
            frameWindow.print();
        };
    }
    var removePrintArea = function (id) {
        $("iframe#" + id).remove();
    };
})(jQuery);
